cmake_minimum_required(VERSION 3.21.2)

execute_process(COMMAND gcc -dumpfullversion -dumpversion OUTPUT_VARIABLE GCC_VERSION)
#message(STATUS "gcc version = ${GCC_VERSION}")

if (GCC_VERSION LESS "4.9.3")
    message(FATAL_ERROR "gcc version need greater than 4.9.3")
endif()

project(vector_index)
execute_process(COMMAND git log -1 --pretty=format:%h . OUTPUT_VARIABLE version)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x -g -O2 -lrt -Wall")

include_directories(./)
include_directories(../include)
include_directories(../include/comm)
include_directories(../include/config_parser)
include_directories(../include/faiss_adapter)
include_directories(../include/rocksdb_adapter)

aux_source_directory(./                     SRC_FILES_FUNC)
aux_source_directory(./config_parser        SRC_FILES_CONFIG_PARSER)
aux_source_directory(./faiss_adapter        SRC_FILES_FAISS_ADAPTER)
aux_source_directory(./rocksdb_adapter      SRC_FILES_ROCKSDB_ADAPTER)

#message("${SRC_FILES_FUNC}")

set(SRC_FILES)
list(APPEND SRC_FILES   ${SRC_FILES_FUNC}
                        ${SRC_FILES_CONFIG_PARSER} 
                        ${SRC_FILES_FAISS_ADAPTER}
                        ${SRC_FILES_ROCKSDB_ADAPTER}
)


#message("${SRC_FILES}")
link_directories(
    ${PROJECT_SOURCE_DIR}/../../../comm
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/faiss/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/rocksdb/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/google/lib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/jsoncpp/lib
)

add_executable(vector_index  ${SRC_FILES})

target_include_directories(vector_index PUBLIC
    ${PROJECT_SOURCE_DIR}/../../../comm
    ${PROJECT_SOURCE_DIR}/../../../3rdlib
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/faiss
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/rocksdb/include
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/rocksdb/logging
    ${PROJECT_SOURCE_DIR}/../../../3rdlib/jsoncpp/include
)

add_definitions(-DACTIVE_GIT_VERSION="${version}" -DMAIN)

target_link_libraries(vector_index faiss rocksdb protobuf protoc jsoncpp common ssl pthread rt dl)
set_target_properties(vector_index PROPERTIES RUNTIME_OUTPUT_DIRECTORY "../bin")
install(TARGETS vector_index RUNTIME DESTINATION bin)
